#!/bin/bash

# 安装依赖项
sudo apt update
sudo apt install -y \
    cmake \
    build-essential \
    libgoogle-glog-dev \
    libgflags-dev \
    libeigen3-dev \
    libsuitesparse-dev \
    libcxsparse3 \
    libcholmod3

# 克隆源码仓库
#git clone https://github.com/ceres-solver/ceres-solver.git
#git clone https://gitee.com/richile/ceres-solver.git
#cd ceres-solver
#git checkout $(git describe --tags)  # 切换到最新稳定版本

# 创建并进入构建目录
mkdir -p build && cd build

# 配置 CMake
cmake -DCMAKE_INSTALL_PREFIX=/usr/local \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_EXAMPLES=OFF \
      -DBUILD_TESTING=OFF \
      ..

# 编译并安装
make -j$(nproc)
sudo make install


echo "Ceres Solver installed successfully"
